﻿using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Diagnostics;

namespace GetPrice
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
            driverService.HideCommandPromptWindow = true;
            ChromeOptions options = new ChromeOptions();

            string price;

            using (IWebDriver driver = new ChromeDriver(driverService, options))
            {
                driver.Url = "http://www.google.com/finance";

                // search field id : gbqfq
                IWebElement searchBox = driver.FindElement(By.Id("gbqfq"));
                searchBox.SendKeys("AMZN");

                // search button id : gbqfb
                driver.FindElement(By.Id("gbqfb")).Click();

                price = driver.FindElement(By.CssSelector("#price-panel span.pr")).Text;

                stopwatch.Stop();
            }

            Console.WriteLine("Current Amazon price is {0}. Elapsed time: {1}", price, stopwatch.Elapsed);

            Console.ReadKey();
        }
    }
}
